<?php
class Controller_Main extends FLEA_Controller_Action
{
    function actionIndex() {
		//$ui =& FLEA::initWebControls();
		if ($_GET['menuName']) $_SESSION['MENUNAME'] = $_GET['menuName'];
		if (!$_SESSION['REALNAME']) {
			redirect(url("Login"));	exit;
		}
		$smarty =& $this->_getView();
		$smarty->display('Main.tpl');
    }

	function actionTop() {
		//$ui =& FLEA::initWebControls();
		$f = & FLEA::getAppInf('menu');
        include $f;
		$smarty =& $this->_getView();
		if ($_SESSION['REALNAME'] != "") $realName = $_SESSION['REALNAME'];
		else $realName = "未登陆";
		FLEA::loadClass('TMIS_Common');
        $compCode = TMIS_Common::getCompCode();
		$smarty->assign('real_name', $realName);
		$smarty->assign('menu', $_sysMenu['menu']);
		$smarty->assign("userId", $_SESSION['USERID']);
        $smarty->assign("compCode", $compCode);
		$smarty->display('MainTop.tpl');
    }

	function actionLeftMenu() {
		$f = & FLEA::getAppInf('menu');
        include $f;
        require_once('Config/NewLogin_config.php');
		// $login = $_login_config;
		$_login_Ip = $_login_config['Login_Ip'];
		$_outTime = $_login_config['timeOut'];

		//如果设置了远程地址,获取远程数据，
		if($_login_Ip!=''){
			$_Url = str_replace(PHP_EOL, '',$_login_Ip);
			//设置超时时间
			$context['http'] = array(
				'timeout'=>$_outTime > 0 ? $_outTime : 3,
				'method' => 'POST'
	    	);
			$json = file_get_contents($_Url, false, stream_context_create($context));
			$_l = json_decode($json,true);
			if($_l['success']){
				$login = $_l['config'];
			}
		}
        $teamCode = FLEA::getAppInf('teamCode');
		if($login['cdUrl']&&$teamCode){
			$list_url = $login['cdUrl'].$teamCode;
		}
		$smarty = & $this->_getView();
		$smarty->assign('menu', $_sysMenu['menu']);
		$smarty->assign("list_url", $list_url);
        $smarty->display('MainLeft.tpl');
    }

	function actionContent() {
		$_modelExample = & FLEA::getSingleton('Model_Index');
		$rowset1 =$_modelExample->findAll("classId=6","dt desc","10");
		$rowset2 =$_modelExample->findAll("classId=2","dt desc","5");
		$rowset3 =$_modelExample->findAll("classId=3","dt desc","5");
		$rowset4 =$_modelExample->findAll("classId=4","dt desc","5");
		$rowset5 =$_modelExample->findAll("classId=5","dt desc","5");

		//通讯录
		$tongxun= & FLEA::getSingleton('Model_Jichu_Tongxun');
		$temp=$tongxun->findAll(null,null,9);
		$temp[]=array(
			'proName'=>'点击查看',
			'tel'=>'<a href="'.url("Jichu_Tongxun","Right").'">更多</a>'
		);
		$i=0;
		foreach($temp as $key=>$v){
			if($key % 2==0 && $key!=0){
				$i++;
			}
			$rowset6[$i][]=$v;
		}
		//dump($temp);exit;
		$smarty = & $this->_getView();
		$pk = $_modelExample->primaryKey;

		$arr_field_info = array(
			"title" =>"标题",
			"buildDate" =>"日期"
		);

		$smarty->assign('arr_field_info',$arr_field_info);
		$smarty->assign('pk', $pk);
		$smarty->assign('arr_field_value1',$rowset1);
		$smarty->assign('arr_field_value2',$rowset2);
		$smarty->assign('arr_field_value3',$rowset3);
		$smarty->assign('arr_field_value4',$rowset4);
		$smarty->assign('arr_field_value5',$rowset5);
		$smarty->assign('arr_field_value6',$rowset6);
        $smarty->display('Welcome.tpl');
    }

	function actionCalculator() {
		$smarty = & $this->_getView();
    	$smarty->display('Calculator.tpl');
	}

	 /**
    * @desc ：获取维护到期情况
    * Time：2019/05/28 16:13:51
    */
    function actionGetMaintenanceInfo(){
	    // 易客宝中的客户名称
	    $ykbName = & FLEA::getAppInf('ykbName');
	    $obj_api = FLEA::getSingleton('Api_RequestYkb');
	    if($ykbName){
	    	$r = $obj_api->callApi(array(
	        'params'=>json_encode(array('compName'=>$ykbName)),
	        // 'isDebug'=>1
	    	));
	    }
	    $ret = json_decode($r,true);
	    $maintenance['success'] = true;
	    $maintenance['showRemind'] = $ret['data'][0]['expire'];
	    $current = time();
		$maintenance['interval'] = ($ret['data'][0]['end_time'] - $current)/(60*60*24);// 间隔天数;
		$maintenance['end_day'] = $ret['data'][0]['end_day'];
	    $maintenance['msg'] = $ret['data'][0]['msg'];
	    // 获取是否有当天的已读记录
		$mMaintenance = & FLEA::getSingleton('Model_Acm_Maintenance');
		if($maintenance['showRemind']){
			if($maintenance['interval']<=0){// 已过期，搜索当天是否有提醒记录，有则不再提醒
				$rows = $mMaintenance->find(array('remindDate'=>date('Y-m-d'),'userId'=>$_SESSION['USERID']));
				if($rows['id']>0) $maintenance['showRemind'] = false;
			}else{// 未过期，但是在30天以内。查找今天前是否有记录生成，有则不再提醒
				$condition[] = array('remindDate',date('Y-m-d'),'<=');
				$condition[] = array('userId',$_SESSION['USERID'],'=');
				$rows = $mMaintenance->find($condition);
				if($rows['id']>0) $maintenance['showRemind'] = false;
			}
		}
		// dump($maintenance);die;
	    echo json_encode($maintenance);exit;
    }

    	/**
	 * @desc ：生成维护提醒记录
	 * Time：2019/10/18 16:37:36
	 * @author Wuyou
	*/
	function actionCreateMaintenance(){
		$mMaintenance = & FLEA::getSingleton('Model_Acm_Maintenance');
		$row = array(
			'userId'     => $_SESSION['USERID']+0,
			'kind'       => $_POST['interval']>0?0:1,
			'remindDate' => date('Y-m-d')
		);
		$mMaintenance->save($row);
		echo json_encode(array('success'=>true));exit;
	}
}


?>